package com.alinu.utils;

import java.util.*;

/**
 * @author chenzuwei
 * @date 2021/3/15
 * @description
 */
public final class CommonUtil {

    private CommonUtil() {
    }

    /**
     * 判断参数是否为空，只要有一个为空，则返回空
     *
     * @param object 参数
     * @return t/f
     */
    public static boolean isNotNull(Object object) {
        if (object == null) {
            return false;
        }
        if (object instanceof Integer) {
            return (Integer) object != 0;
        }
        if (object instanceof Long) {
            return (Long) object != 0;
        }
        if (object instanceof String) {
            return !"".equals(object.toString().trim());
        }
        if (object instanceof Collection) {
            return !((Collection) object).isEmpty();
        }
        if (object instanceof Map) {
            return !((Map) object).isEmpty();
        }
        return true;
    }

    /**
     * @param o
     * @return
     */
    public static boolean isNull(Object o) {
        return !isNotNull(o);
    }

    /**
     * @param str
     * @return
     */
    public static List<String> strToList(String str) {
        if (CommonUtil.isNotNull(str)) {
            String[] s = str.split(",");
            return Arrays.asList(s);
        }
        return new ArrayList<>();
    }
}
